#include <stdio.h>
#include <stdlib.h>
#include "Structs.h"
#include "Pong3D.h"
#include "glfont.h"
#include <GL/glut.h>
#include <math.h>
#include <Windows.h>

float scaleFactor = 0.1;
float isGrowing = 1;

/*
Function Name: incrementScaleFactor
Description: changes the rate at which score text are scaled during end game
Inputs:		null
returns:	null
*/
void incrementScaleFactor()
{
	if(isGrowing == 1)
	{
		scaleFactor += 0.02;
		if(scaleFactor > 1.0)
		{
			isGrowing = 0;
		}
	}
	else
	{
		scaleFactor -= 0.02;
		if(scaleFactor <= 0.6)
		{
			isGrowing = 1;
		}
	}
}
void drawScore(void){
	GLFONT font;
	char playerScore[100] = "Player: ";
	char scoreBuffer[10];
	char computerScore[100] = "Computer: ";

	if(!glFontCreate(&font, "font.glf", 0))
	{
		return;
	}

	glMatrixMode(GL_MODELVIEW);
	glColor4fv(COLOR_WHITE);
	glPushMatrix();
	glFontBegin(&font);
	glScalef(0.30, 0.3, 1.0);
	glEnable(GL_TEXTURE_2D);

	if(_state == GAME_WIN)
	{
		glScalef(scaleFactor, scaleFactor, scaleFactor);
		if(_players[0].score > _players[1].score)
		{
			glFontTextOut("You Win", -5, -10, 4);
		}
		else
		{
			glFontTextOut("You Lose", -5, -10, 4);
		}
		//glScalef(-scaleFactor, -scaleFactor, -scaleFactor);
		
	}

	itoa(_players[0].score, scoreBuffer, 10);
	strcat(playerScore, scoreBuffer);

	itoa(_players[1].score, scoreBuffer, 10);
	strcat(computerScore, scoreBuffer);
	glFontTextOut(playerScore, -23, 15, 4);
	glFontTextOut(computerScore, 10, 15, 4);
		
	
	glPopMatrix();
	glPushMatrix();
	glScalef(0.30, 0.3, 1.0);
	glPopMatrix();
	glFontEnd();
	glFontDestroy(&font);
	glDisable(GL_TEXTURE_2D);

	incrementScaleFactor();
}